package com.fowo.api.controller.purchase.interfaceImp;

import com.fowo.api.model.sourcing.manage.SourcingManageNoIncompleteAction;
import com.fowo.api.model.sourcing.manage.SourcingManageSNoIncompleteAction;
import com.fowo.api.model.sourcing.manage.SourcingManageVo;
import com.fowo.api.service.impl.SourcingManageServiceImpl;
import lombok.Data;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.util.List;

@Component
public class sourcingManageNoIncompleteAction implements SourcingManageSNoIncompleteAction {
    @Resource
    private SourcingManageServiceImpl sourcingManageService;


    @Transactional(rollbackFor = Exception.class)
    @Override
    public void run(List<Long> idList) throws Exception {
        for(int i=0;i<idList.size();i++){
            Long aLong = idList.get(i);
            handData(aLong);
        }
    }

    private void handData(Long aLong) throws Exception {
        SourcingManageVo voById = sourcingManageService.getVoById(aLong);
        Assert.isTrue(voById.getState().equals("0"),"违规操作");
        voById.setState("1");
        sourcingManageService.update(voById);
    }
}
